// components/music-list/music-list.js
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    musiclist: Array,
    needTouchMove: {
      type: Boolean,
      value: false
    },
    btnType: {
      type: String,
      value: 'normal'
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    playingId: -1,
    moveIndex: -1,
    moveType: 'noMove'
  },

  pageLifetimes: {
    show () {
      this.setData({
        playingId: parseInt(app.getPlayingMusicId())
      })
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onSetLike () { // 设置收藏
      wx.showModal({
        title: '好气呦',
        content: '收藏功能还没做好呦\r\n别着急~~',
        showCancel: false,
        confirmText: '再等等吧',
        success: (res) => {
          if (res.confirm) {
            this.setData({ moveIndex: -1, moveType: 'noMove' })
          }
        }
      })
    },
    onSetDel (event) {
      let selectId = event.target.dataset.selectid
      if (selectId == this.data.playingId) {
        wx.showModal({
          title: '不能删除呦',
          content: '当前音乐正在播放中\r\n暂时还不能删除呦~',
          showCancel: false,
          confirmText: '等会再删',
        })
      }
      this.triggerEvent('delateListItem', event.target.dataset.index)
    },
    onSelect (event) {
      const datasetData = event.currentTarget.dataset
      const musicid = datasetData.musicid
      this.setData({
        moveIndex: -1,
        moveType: 'noMove',
        playingId: musicid
      })
      wx.navigateTo({
        url: `../../pages/player/player?musicId=${musicid}&index=${datasetData.index}`
      })
    },
    touchstart (e) {
      if (!this.properties.needTouchMove) return
      app.touch._touchstart(e)
      if (this.data.moveIndex != e.currentTarget.dataset.index) {
        this.setData({ moveIndex: -1, moveType: 'noMove' })
        return
      }
      this.setData({ moveIndex: e.currentTarget.dataset.index })
    },
    // 移动
    touchmove (e) {
      if (!this.properties.needTouchMove) return
      let moveObj = app.touch._touchmove(e)
      if (moveObj.index != this.data.moveIndex) {
        this.setData({ moveIndex: moveObj.index })
      }
      // if (moveObj && this.data.moveObj != 'noMove') {
      //   console.log('sdasddsads')
      //   this.setData({ moveType: 'noMove' })
      // }
      if (moveObj.type != this.data.moveType) {
        this.setData({ moveType: moveObj.type })
      }
    }
  }
})
